// 模拟常用的高阶函数: map every some

//map
const map = (arr, fn) => {
  let res = [];
  for (let val of arr) {
    res.push(fn(val));
  }
  return res;
};

//test
// let arr = [1, 2, 3, 4, 5, 6];
// arr = map(arr, (v) => v * v);
// console.log(arr)

//every
const every = (arr, fn) => {
  let res = true
  for(let val of arr){
    res = fn(val)
    if(!res){
      break
    }
  }
  return res
}

//test
// let arr = [12,3,45,342,4]
// let res = every(arr, v => v > 13)
// console.log(res)


//some
const some = (arr,fn) => {
  let res = false
  for(let val of arr){
    res = fn(val)
    if(res){
      break
    }
  }
  return res
}

//test
let arr = [12,3,45,342,4]
let res = some(arr, v => v > 13)
console.log(res)